Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
sync-child-process
Advanced tools
sync-child-process
This package exposes a SyncChildProcess
class that allows Node.js to run a
subprocess synchronously and interactively.
Use new SyncChildProcess()
to start running a subprocess. This supports the
same API as child_process.spawn()
other than a few options. You can send
input to the process using process.stdin
, and receive events from it
(stdout, stderr, or exit) using process.next()
. This implements the
iterator protocol, but not the iterable protocol because it's intrinsically
stateful.
import {SyncChildProcess} from 'sync-child-process';
// or
// const {SyncChildProcess} = require('sync-child-process');
const node = new SyncChildProcess('node', ['--interactive']);
for (;;) {
if (node.next().value.data.toString().endsWith('> ')) break;
}
node.stdin.write("41 * Math.pow(2, 5)\n");
console.log((node.next().value.data.toString().split("\n")[0]));
node.stdin.write(".exit\n");
console.log(`Node exited with exit code ${node.next().value.code}`);
See the sync-message-port
documentation for an explanation of why running
code synchronously can be valuable even in an asynchronous ecosystem like
Node.js
child_process.spawnSync()
?Although Node's built-in child_process.spawnSync()
function does run
synchronously, it's not interactive. It only returns once the process has run to
completion and exited, which means it's not suitable for any long-lived
subprocess that interleaves sending and receiving data, such as when using the
embedded Sass protocol.
Disclaimer: this is not an official Google product.
1.0.2
FAQs
Run a subprocess synchronously and interactively in Node.js
The npm package sync-child-process receives a total of 231,634 weekly downloads. As such, sync-child-process popularity was classified as popular.
We found that sync-child-process demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.